How to rip background pictures from diskmags

By Adok/Hugi

You have a diskmag, you know how to make screenshots (using the Print Screen key for example), now you want to extract a background picture from this mag. This may be useful, for example, if you want to release a fake issue of this magazine. ;-) This task is not completely trivial, how could you solve it? If you make a screenshot, you usually get the background picture plus text over it. But you don't want to have the text. In most mags it isn't possible for the reader just to view the background picture without text. (One exception is Zine #12.) If that were possible, it would be easy because then you would only have to switch to this mode and then make the screenshot. However, how is it done otherwise?

First of all you need several screenshots of different pages. In these screenshots, different areas of the screen are occupied by text. Where a pixel is black in one screenshot, the same pixel may be in a grayshade colour in the other screenshot. Of course, in order to extract the background, you choose the pixel from the screenshot where it is not part of the text. Supposed that the text colour is black and the background is gray, you pick the pixel from the screenshot where it is gray. You must do such a comparison and selection pixel per pixel. It is a major pain in the ass to do this manually with a standard graphics program such as Photoshop or MS Paint. It is much more efficient to do this with a self-written tool. Especially because you can implement an algorithm that automatically chooses the right shade of the pixel. How is this done?

It's not difficult: Backgrounds usually have a low contrast. So the RGB values of neighbouring pixels don't differ much. In contrast to this, text has a high contrast to the background. So in order to detect which of two images contains background at a certain pixel position, you have to compare the contrast. That can be done by computing the mean RGB value of the surrounding pixels and comparing it with the RGB value of the pixel in question. The image with the lower difference is the one that contains the background.

If you scan all pixels from top to down, left to right, you can take the RGB values of the upper-left, upper, upper-right and left neighbouring pixels. Add all red, all green, all blue values together and divide them by the number of pixels to get the mean values.

To demonstrate that this method works, here's a screenshot from the latest Pain diskmag (#59):

By means of several (six) screenshots, my program extracted the following background picture:

It's not perfect yet but already quite good. And the more screenshots I use, the better it becomes.

The program is included in the bonus pack (PictureComparison1).

Adok/Hugi